package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbEventType;
import com.ag.common.BaseAction;
import com.ag.zlw.service.EventTypeService;
import com.ag.common.IDUtil;

/**
 * 事件类型
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("EventTypeAction")
public class EventTypeAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "EventTypeService")
	private EventTypeService service;
	private List<TbEventType> eventTypeList;

	private String message;
	private String etId;
	private String etEventType;

	TbEventType tbEventType = new TbEventType();

	public String find() {
		try {
			eventTypeList = service.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbEventType.setEtId(etId);
		try {
			service.delete(tbEventType);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		tbEventType.setEtEventType(etEventType);
		tbEventType.setA(IDUtil.PRESERVE);
		try {
			service.save(tbEventType);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbEventType.setEtId(etId);
		tbEventType.setEtEventType(etEventType);
		tbEventType.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbEventType);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public void setEventTypeList(List<TbEventType> eventTypeList) {
		this.eventTypeList = eventTypeList;
	}

	public List<TbEventType> getEventTypeList() {
		return eventTypeList;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getMessage() {
		return message;
	}

	public String getEtId() {
		return etId;
	}

	public void setEtId(String etId) {
		this.etId = etId;
	}

	public String getEtEventType() {
		return etEventType;
	}

	public void setEtEventType(String etEventType) {
		this.etEventType = etEventType;
	}
}
